package com.andyage.admin.action;

import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.andyage.admin.bean.AdfeedbackBean;
import com.andyage.admin.service.IAdfeedbackService;
import com.andyage.util.DateUtil;

@Controller
@RequestMapping("/admin")
public class AdfeedbackAction {
	@Resource
	private IAdfeedbackService feedbackService;
	String CONTENT_TYPE = "text/html;charset=utf-8";

	@RequestMapping("/updateFeedBackInfo")
	public void updateFeedBackInfo(HttpServletResponse response, AdfeedbackBean feedback,HttpSession session) throws Exception {
		feedback.setFbAnswerTime(new Date());
		feedback.setFbStaffId((String)session.getAttribute("AccountId"));
		//feedback.setStaffName((String)session.getAttribute("staffAccount"));
		String json = feedbackService.updateFeedBackInfo(feedback);
		response.setContentType(CONTENT_TYPE);
		response.getWriter().print(json);
	}

	@RequestMapping("/queryFeedBackInfo")
	public void queryFeedBackInfo(HttpServletResponse response,HttpServletRequest request, AdfeedbackBean feedback) throws Exception {
		String startDate=request.getParameter("sstartDate");
		if(startDate!=null &&!"".equals(startDate)){
			feedback.setStartDate(DateUtil.getDate(startDate,"yyyy-MM-dd"));
		}
		String endDate=request.getParameter("sendDate");
		if(endDate!=null && !"".equals(endDate)){
			feedback.setEndDate(DateUtil.getDate(endDate,"yyyy-MM-dd"));
		}
		System.out.println(feedback.getStartDate());
		System.out.println(feedback.getEndDate());
		String json = feedbackService.queryFeedBackInfo(feedback);
		response.setContentType(CONTENT_TYPE);
		response.getWriter().print(json);
	}

	@RequestMapping("/deleteFeedBackInfo")
	public void deleteFeedBackInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
		String fbId = request.getParameter("fbId");
		String json = feedbackService.deleteFeedBackInfo(fbId);
		response.setContentType(CONTENT_TYPE);
		response.getWriter().print(json);
	}
}
